query-insights.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from 'ui'
  2. import { QueryInsights } from '@/components/interfaces/QueryInsights/QueryInsights'
  3. import { REPORT_DATERANGE_HELPER_LABELS } from '@/components/interfaces/Reports/Reports.constants'
  4. import { DefaultLayout } from '@/components/layouts/DefaultLayout'
  5. import ObservabilityLayout from '@/components/layouts/ObservabilityLayout/ObservabilityLayout'
  6. import { DatabaseSelector } from '@/components/ui/DatabaseSelector'
  7. import { DocsButton } from '@/components/ui/DocsButton'
  8. import { useReportDateRange } from '@/hooks/misc/useReportDateRange'
  9. import { DOCS_URL } from '@/lib/constants'
  10. import type { NextPageWithLayout } from '@/types'
  11. const PRESETS = [
  12. REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES,
  13. REPORT_DATERANGE_HELPER_LABELS.LAST_3_HOURS,
  14. REPORT_DATERANGE_HELPER_LABELS.LAST_24_HOURS,
  15. ]
  16. const QueryInsightsReport: NextPageWithLayout = () => {
  17. const { selectedDateRange, datePickerValue, datePickerHelpers, handleDatePickerChange } =
  18. useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
  19. const handleSelect = (text: string) => {
  20. const helper = datePickerHelpers.find((h) => h.text === text)
  21. if (helper) {
  22. handleDatePickerChange({ from: helper.calcFrom(), to: helper.calcTo(), isHelper: true, text })
  23. }
  24. }
  25. return (
  26. <div className="h-full flex flex-col">
  27. <div className="w-full mb-0 flex lg:items-center justify-between gap-4 py-2 px-6 lg:flex-row flex-col border-b lg:h-[48px]">
  28. <h3 className="text-foreground text-xl prose">Query Insights</h3>
  29. <div className="flex items-center gap-2 flex-wrap">
  30. <DocsButton
  31. href={`${DOCS_URL}/guides/platform/performance#examining-query-performance`}
  32. />
  33. <DatabaseSelector />
  34. <Select
  35. value={datePickerValue.isHelper ? datePickerValue.text : undefined}
  36. onValueChange={handleSelect}
  37. >
  38. <SelectTrigger size="tiny" className="w-[150px]">
  39. <SelectValue />
  40. </SelectTrigger>
  41. <SelectContent align="end">
  42. {PRESETS.map((label) => (
  43. <SelectItem key={label} value={label}>
  44. {label}
  45. </SelectItem>
  46. ))}
  47. </SelectContent>
  48. </Select>
  49. </div>
  50. </div>
  51. <QueryInsights dateRange={selectedDateRange} />
  52. </div>
  53. )
  54. }
  55. QueryInsightsReport.getLayout = (page) => (
  56. <DefaultLayout>
  57. <ObservabilityLayout title="Query insights">{page}</ObservabilityLayout>
  58. </DefaultLayout>
  59. )
  60. export default QueryInsightsReport